﻿namespace Common.ChartDrawing
{
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Shapes;

    public static class PrimitivesDrawer
    {
        public static Line GridVertical(double x)
        {
            Line line = new Line();
            line.Stroke = new SolidColorBrush(Constants.GridLinesColor);
            line.StrokeThickness = 1;
            line.X1 = line.X2 = x;
            line.Y1 = 0;
            line.Y2 = Constants.Height;
            Canvas.SetZIndex(line, 1);
            return line;
        }

        public static Line GridHorizontal(double y)
        {
            Line line = new Line();
            line.Stroke = new SolidColorBrush(Constants.GridLinesColor);
            line.StrokeThickness = 2;
            line.Y1 = line.Y2 = y;
            line.X1 = Constants.FieldsWidth;
            line.X2 = Constants.Width - Constants.FieldsWidth + 2;
            Canvas.SetZIndex(line, 1);
            return line;
        }

        public static Line SolidEndOfBlockLine(double y)
        {
            Line line = new Line();
            line.Stroke = new SolidColorBrush(Constants.GridLinesColor);
            line.StrokeThickness = 2;
            line.X1 = 0;
            line.X2 = Constants.Width;
            line.Y1 = line.Y2 = y;
            Canvas.SetZIndex(line, 3);
            return line;
        }

        public static Line EndOfBlockLine(double y)
        {
            Line line = new Line();
            line.Stroke = new SolidColorBrush(Constants.GridLinesColor);
            line.StrokeThickness = 2;
            line.X1 = 0;
            line.X2 = Constants.Width;
            line.Y1 = line.Y2 = y;
            line.StrokeDashArray = new DoubleCollection() { 5, 4 };
            Canvas.SetZIndex(line, 1);
            return line;
        }

        public static TextBlock DateLabel(double y, DateTime time)
        {
            TextBlock dateLabel = new TextBlock();
            dateLabel.FontSize = 12;
            dateLabel.Foreground = new SolidColorBrush(Constants.DatesColor);
            dateLabel.Text = time.ToShortDateString();
            dateLabel.Margin = new Thickness(Constants.Width - 65, y - 5,
                dateLabel.Margin.Right, dateLabel.Margin.Bottom);
            Canvas.SetZIndex(dateLabel, 4);
            return dateLabel;
        }

        public static TextBlock TimeLabel(double y, DateTime time)
        {
            TextBlock timeLabel = new TextBlock();
            timeLabel.FontSize = 12;
            timeLabel.Foreground = new SolidColorBrush(Constants.DatesColor);
            timeLabel.Text = time.ToLongTimeString();
            timeLabel.Margin = new Thickness(1, y - 5, timeLabel.Margin.Right, timeLabel.Margin.Bottom);
            Canvas.SetZIndex(timeLabel, 4);
            return timeLabel;
        }
    }
}